/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package personal.dao;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import personal.utility.DBUtility;

/**
 *
 * @author PHATNBSE61057
 */
public class RoleDAO implements Serializable {

    private final DBUtility utility = new DBUtility();

    public RoleDAO() {
    }

    public String getRoleNameByID(int roleID) {
        Connection con = null;
        PreparedStatement pst = null;
        ResultSet rs = null;
        try {
            con = utility.makeConnection();
            String query = "SELECT * FROM Role WHERE RoleID = ?";
            pst = con.prepareStatement(query);
            pst.setInt(1, roleID);
            rs = pst.executeQuery();
            if (rs.next()) {
                String roleName = rs.getString("Name");
                return roleName;
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
                if (pst != null) {
                    pst.close();
                }
                if (con != null) {
                    con.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}
